package com.cloudnews;

import java.io.Serializable;
import java.util.Date;

import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Named;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.ws.rs.core.MediaType;

import org.jboss.resteasy.client.ClientRequest;

import com.cloudnews.constant.CloudType;
import com.cloudnews.model.news.Stories;

@Named("createStoryHome")
@RequestScoped
public class CreateStoryHome implements Serializable {
	@PersistenceContext
	private EntityManager em;
	
	private Stories story = new Stories();
	
	public CloudType[] getCloudType(){
		return CloudType.values();
	}
	
	public void saveStory(){
		ClientRequest request = new ClientRequest("https://maps.googleapis.com/maps/api/place/search/json?location="+story.getLatitude()+","+story.getLongitude()+"&radius=25&sensor=false&key=AIzaSyDm9yzU7KAwopw4lziTDREDte4axVkExj0");
		request.accept(MediaType.APPLICATION_JSON);
		try{
		String response = request.postTarget(String.class);
		System.out.println("response "+response);
		}catch(Exception e){
			e.printStackTrace();
		}
		System.out.println(" logtitude "+story.getLongitude());
		story.setPostedDate(new Date());
		em.persist(story);
	}

	public Stories getStory() {
		return story;
	}

	public void setStory(Stories story) {
		this.story = story;
	}
	
	
}
